package test.laji;


import java.nio.Buffer;
import java.nio.channels.SelectionKey;
import java.util.*;

public class XiangXun {

    public  static  void main(String[] arh0)
    {
        sanJiao();
    }

    public static  void  sanJiao(){

        Map<String, String> hashMap = new HashMap();
        Map<String, String> linkedHashMap = new LinkedHashMap();
        hashMap.put("1111", "a");
        hashMap.put("3333", "b");
        hashMap.put("2222", "c");
        hashMap.put("4444", "d");
        hashMap.put("5555", "e");
        linkedHashMap.put("11", "张三");
        linkedHashMap.put("22", "李四");
        linkedHashMap.put("33", "网二");
//        for (Map.Entry<String, String> entry : hashMap.entrySet()) {
//            System.out.println("hashKey= " + entry.getKey() + "\t" + "hashValue = " + entry.getValue());
//        }
//        for (Map.Entry<String, String> entry : linkedHashMap.entrySet()) {
//            System.err.println("linkKey= " + entry.getKey() + "\t" + "linkValue = " + entry.getValue());
//        }

//        Iterator iterator=linkedHashMap.entrySet().iterator();
//
//
//
//        System.out.println(iterator.next());
//
//
//
        Collection<Integer> collection=new ArrayList<>();
        ((ArrayList<Integer>) collection).add(1);
        ((ArrayList<Integer>) collection).add(2);
        ((ArrayList<Integer>) collection).add(3);
        for(Integer  i: collection)
        {
            System.out.println(i);
        }
        collection.forEach(ele -> System.out.println(ele));
        Iterator<Integer> it = collection.iterator() ;
        while(it.hasNext()) {
            Integer str = it.next() ;
            if(str.equals("javaweb")) {
                it.remove();//此处删除集合中的一个元素
            }
            System.out.println(str);
        }
        it.forEachRemaining(str -> System.out.println(str));
        System.out.println(collection);


//         Object[] objects=new Object[1];
        ((ArrayList<Integer>) collection).add(0,123);
//        System.out.println(collection.l);


    }

    public boolean containsNearbyDuplicate(int[] nums, int k) {
        Set<Integer> s = new HashSet<Integer>();
        for(int i=0;i<nums.length;i++)
        {
            if (s.contains(nums[i])) return true;
            s.add(nums[i]);
            if (s.size()>k)
            {
                s.remove(nums[i-k]);
            }
        }
        return false;

    }
}
